package cn.snmp.mutual.nms.mibs;

import cn.snmp.mutual.nms.SnmpOID;
import cn.snmp.mutual.nms.SnmpUtils;
import java.util.*;

public class MibTrap
{
    protected Hashtable m_propreties;
    protected MibModule m_module;
    
    public MibTrap(final MibModule module, final Hashtable proteties) {
        this.m_propreties = null;
        this.m_module = null;
        this.m_module = module;
        this.m_propreties = proteties;
    }
    
    public String getDescription() {
        final Object object = this.m_propreties.get("Description");
        if (object == null) {
            return "";
        }
        return object.toString();
    }
    
    public SnmpOID getEnterprise() {
        final Object object = this.m_propreties.get("Enterprise");
        if (object == null) {
            return null;
        }
        final SnmpOID oid = new SnmpOID(object.toString());
        return oid;
    }
    
    public String getEnterpriseString() {
        final Object object = this.m_propreties.get("EnterpriseString");
        if (object == null) {
            return "";
        }
        return object.toString();
    }
    
    public String getModuleName() {
        return this.m_module.toString();
    }
    
    public String getName() {
        final Object object = this.m_propreties.get("Name");
        if (object == null) {
            return "";
        }
        return object.toString();
    }
    
    public String getReference() {
        final Object object = this.m_propreties.get("Reference");
        if (object == null) {
            return "";
        }
        return object.toString();
    }
    
    public byte getTrapType() {
        final Object object = this.m_propreties.get("TrapType");
        if (object == null) {
            return 0;
        }
        return Byte.parseByte(object.toString());
    }
    
    public int getValue() {
        final Object object = this.m_propreties.get("Value");
        if (object == null) {
            return 0;
        }
        return Integer.parseInt(object.toString());
    }
    
    public Vector getVariables() {
        final Object object = this.m_propreties.get("Variables");
        if (object == null) {
            return null;
        }
        return (Vector)object;
    }
    
    @Override
    public String toString() {
        return this.getName();
    }
    
    public String toTagString() {
        final StringBuffer stringbuffer = new StringBuffer();
        stringbuffer.append(this.getName() + " " + SnmpUtils.getString("TRAP-TYPE"));
        if (this.getEnterprise() != null) {
            stringbuffer.append("\n\t" + SnmpUtils.getString("ENTERPRISE") + "\t" + this.getEnterprise());
        }
        else if (this.getEnterpriseString() != null) {
            stringbuffer.append("\n\t" + SnmpUtils.getString("ENTERPRISE") + "\t" + this.getEnterpriseString());
        }
        if (this.getVariables() != null) {
            stringbuffer.append("\n\t" + SnmpUtils.getString("VARIABLES") + "\t{ ");
            final Enumeration enumeration = this.getVariables().elements();
            while (enumeration.hasMoreElements()) {
                stringbuffer.append(String.valueOf(enumeration.nextElement()) + " ");
            }
            stringbuffer.append("}");
        }
        if (this.getDescription() != null) {
            stringbuffer.append("\n\t" + SnmpUtils.getString("DESCRIPTION") + "\t" + this.getDescription());
        }
        if (this.getReference() != null) {
            stringbuffer.append("\n\t" + SnmpUtils.getString("REFERENCE") + "\t" + this.getReference());
        }
        stringbuffer.append("\n\t::=\t" + this.getValue());
        return stringbuffer.toString();
    }
}
